package com.cnyz.config;

import com.cnyz.properties.UploadConfigProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UploadConfig implements WebMvcConfigurer {


    private  UploadConfigProperties uploadConfigProperties;

    public UploadConfig(UploadConfigProperties uploadConfigProperties) {
        this.uploadConfigProperties = uploadConfigProperties;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 这里用配置类的imgPath属性
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + uploadConfigProperties.getImgPath());
    }
}
